home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-68k-src / machines / amiga68k / libsrc / amigalib / createtask.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  2KB  |  67 lines

  1. /*
  2. ** compiles with inline only in large data! AddTask() uses too many
  3. ** nonscratch registers :( use of assembler version is recommended
  4. */
  5. #include <exec/tasks.h>
  6. #include <exec/memory.h>
  7. #include <exec/execbase.h>
  8. #include <clib/alib_protos.h>
  9. #include <proto/exec.h>
  10.  
  11. extern struct ExecBase *SysBase;
  12.  
  13. struct newMemList
  14. {
  15.   struct Node nml_Node;
  16.   UWORD nme_NumEntries;
  17.   struct MemEntry nml_ME[2];
  18. };
  19.  
  20. const struct newMemList MemTemplate =
  21. { {0,},
  22.   2,
  23.   { {MEMF_CLEAR|MEMF_PUBLIC, sizeof(struct Task)},
  24.     {MEMF_CLEAR, 0} }
  25. };
  26.  
  27. struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize)
  28. {
  29.   struct Task *newtask,*task2;
  30.   struct newMemList nml;
  31.   struct MemList *ml;
  32.  
  33.   stacksize=(stacksize+3)&~3;
  34.   {
  35.     long *p1,*p2;
  36.     int i;
  37.  
  38.     for (p1=(long *)&nml,p2=(long*)&MemTemplate,i=7; i; *p1++=*p2++,i--) ;
  39.     *p1=stacksize;
  40.   }
  41. /*  if (!(((unsigned int)ml=AllocEntry((struct MemList *)&nml)) & (1<<31)))*/
  42. /*  was dieser gcc alles als lvalue durchgehen laesst...    */
  43.   ml=AllocEntry((struct MemList *)&nml);
  44.   if(!((unsigned int)ml&(1<<31)))
  45.   {
  46.     newtask=ml->ml_ME[0].me_Addr;
  47.     newtask->tc_Node.ln_Type=NT_TASK;
  48.     newtask->tc_Node.ln_Pri=pri;
  49.     newtask->tc_Node.ln_Name=name;
  50.     newtask->tc_SPReg=(APTR)((ULONG)ml->ml_ME[1].me_Addr+stacksize);
  51.     newtask->tc_SPLower=ml->ml_ME[1].me_Addr;
  52.     newtask->tc_SPUpper=newtask->tc_SPReg;
  53.     NewList(&newtask->tc_MemEntry);
  54.     AddHead(&newtask->tc_MemEntry,(struct Node *)ml);
  55.     task2=(struct Task *)AddTask(newtask,initpc,0);
  56.     if (SysBase->LibNode.lib_Version>36 && !task2)
  57.     {
  58.       FreeEntry(ml); newtask=NULL;
  59.     }
  60.   }
  61.   else
  62.     newtask=NULL;
  63.  
  64.   return newtask;
  65. }
  66.  
  67.